getBytes("gb2312")是干什么的?

来源:百度知道 编辑:UC知道 时间:2024/05/05 22:51:28
在jsp书中看到以下代码段:
<%!String trans(String chi){
String result=null;
byte temp[];
try{temp=chi.getBytes("gb2312");
result=new String(temp);}
catch(java.io.UnsupportedEncodingException e){
system.out.println(e.toString());
}return result;
}%>
这个方法是实现什么功能的?输入的chi和输出的result字符串有什么不同?

实现字符编码的转换,chi的编码方式我们不知道,所以要正确显示成中文就必须对编码进行转换"gb2312"是中文的一种编码方式。

实现字符编码的转换,防止乱码的

实现转码,如果有中文的话
chi为乱码,result为中文